package com.yaowk.common.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.kit.LogKit;
import com.jfinal.render.RenderFactory;
import com.yaowk.common.model.element.RespBody;

/**
 * Created by yaowk on 17-9-4.
 */
public class DevErrorInterceptor extends RenderFactory implements Interceptor {
    @Override
    public void intercept(Invocation invocation) {
        try {
            invocation.invoke();
        } catch (Throwable e) {
            RespBody respBody = new RespBody();
            respBody.setCode("500");
            respBody.setMsg(e.getMessage());
            invocation.getController().renderJson(respBody);
            LogKit.info("", e);
        }
    }
}
